package com.sasis.model;

public class RoleHandlePermission extends BaseEntity implements Permission {

	private static final long serialVersionUID = 1L;
	
	private Long roleId;
	
	private Long handleId;
	
	private boolean allow;
	
	public RoleHandlePermission() {
		
		
	}
	public RoleHandlePermission(Long roleId, Long handleId, boolean allow) {
		this.roleId = roleId;
		this.handleId = handleId;
		this.allow = allow;
	}
	
	public RoleHandlePermission(Permission permission) {
		this.roleId = permission.getPrincipal().getId();
		this.handleId = permission.getSubject().getId();
		this.allow = permission.isAllow();
	}
	
	public boolean isAllow() {
		return allow;
	}

	public void setAllow(boolean allow) {
		this.allow = allow;
	}

	public Long getHandleId() {
		return handleId;
	}

	public void setHandleId(Long handleId) {
		this.handleId = handleId;
	}

	public Long getRoleId() {
		return roleId;
	}

	public void setRoleId(Long roleId) {
		this.roleId = roleId;
	}
	
	public Principal getPrincipal() {
		return new BasePrincipal(roleId, true);
	}

	public Subject getSubject() {
		return new BaseSubject(handleId, false);
	}
}
